<template>
	<view>
		<web-view ref="view" src="/hybrid/html/local.html" @message="getMessage" @onPostMessage="onPostMessage">
		</web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				line: null,
				lineStr: '',
				currentWebview: null,
				timer: null
			}
		},
		onLoad(option) {
			this.lineStr = option.json;
			this.line = JSON.parse(option.json)
		},
		onUnload() {
			clearInterval(this.timer)
		},
		methods: {
			getMessage(e) {
				if (e.detail.data[0].action === 'init') {
					try {
						const currentWebview = this.$scope.$getAppWebview();
						const webview = currentWebview.children()[0];
						webview.evalJS('doMap(\'' + this.lineStr + '\')')
						this.timer = setInterval(() => {
							uni.getLocation({
								type: 'wgs84',
								success(res) {
									webview.evalJS('updateCarPosition(' + res.longitude + ',' + res
										.latitude + ')');

								}
							});
						}, 1000)
					} catch (e) {
						console.log(e)
					}
				}
			},
			onPostMessage(e) {
				console.log(e.detail.data)
			},
		}
	}
</script>

<style>

</style>
